#include<iostream>
#include<string>
using namespace std;
string s;
typedef long long LL;
const int N = 1e5 + 10;
LL f[N];
int a[N];
int n;
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)cin >> a[i];
	cin >> s;
	s = " " + s;
	for (int i = 2; i <= n; i++) {
		f[i] = f[i - 1];
		if (s[i] != s[i - 1]) {
			f[i] = max(f[i - 1], f[i - 2] + a[i] + a[i - 1]);
			//cout << "f[i]==" << f[i] << endl;
		}
	}
	cout << f[n] << endl;
	return 0;
}